package com.bocai.controller;

import com.bocai.bean.CashInfo;
import com.bocai.bean.RechargeInfo;
import com.bocai.service.ICashInfoService;
import com.bocai.service.IRechargeInfoService;
import com.bocai.utils.CodeEnum;
import com.bocai.utils.DateUtils;
import com.bocai.utils.RandomUtils;
import com.bocai.utils.ResponseData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;

/**
 * Created by jyf on 18/4/13.
 */
@Controller
@RequestMapping("cashInfo")
public class CashInfoController {

    @Autowired
    private ICashInfoService cashInfoService;

    @ApiOperation(value = "提现钱数", notes = "提现钱数")
    @RequestMapping(value = "/saveCashInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData saveCashInfo(Integer userId, BigDecimal money, String payString) {
        ResponseData data = new ResponseData();
        if (null == userId || userId < 0) {
            data.setCodeEnum(CodeEnum.CODE_90002);
        } else {
            CashInfo cashInfo = new CashInfo();
            cashInfo.setUserId(userId);
            String orderNum = RandomUtils.getOrderNumber();
            cashInfo.setCashNumber(orderNum);
            cashInfo.setCashMoney(money);
            cashInfo.setPaymentType(payString);
            cashInfo.setCashState(1);
            cashInfo.setCreateTime(new Date());
            cashInfo.setCashArrivalMoney(new BigDecimal(0));
            int num = cashInfoService.insertSelective(cashInfo);
            if (num == 1) {
                data.setCodeEnum(CodeEnum.SUCCESS);
            } else if (num == 2) {
                data.setCodeEnum(CodeEnum.CODE_10009);
            } else if (num == 3) {
                data.setCodeEnum(CodeEnum.CODE_90005);
            } else {
                data.setCodeEnum(CodeEnum.CODE_10003);
            }
        }
        return data;
    }

    @ApiOperation(value = "确定提现钱数 确定1   驳回2", notes = "确定提现钱数 确定1   驳回2")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "cashId", dataType = "integer", value = "提现Id", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "flag", dataType = "integer", value = "确定1   驳回2", defaultValue = "1"),
    })
    @RequestMapping(value = "/saveDetermineCashInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData saveDetermineUserInfo(Integer cashId, Integer flag) {
        ResponseData data = new ResponseData();
        if (null == cashId || cashId < 0 || flag > 2) {
            data.setCodeEnum(CodeEnum.CODE_90002);
        } else {
            int num = cashInfoService.updateCashInfo(cashId, flag);
            if (num == 1) {
                data.setCodeEnum(CodeEnum.SUCCESS);
            } else if (num == 2) {
                data.setCodeEnum(CodeEnum.CODE_90005);
            } else {
                data.setCodeEnum(CodeEnum.CODE_1);
            }
        }
        return data;
    }


    @ApiOperation(value = "提现列表", notes = "提现列表")
    @RequestMapping(value = "/findCashInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData findCashInfo() {
        ResponseData data = new ResponseData();
        data.setCodeEnum(CodeEnum.SUCCESS);
        data.setResults(cashInfoService.findAllCashInfo());
        return data;
    }
}
